extends Control

@onready var name_label = $name_label
@onready var 说明 = $"说明"
@onready var color_rect = $ColorRect

const 品质颜色:Dictionary={
	0:Color.AZURE,
	1:Color.LIME_GREEN,
	2:Color.DEEP_SKY_BLUE,
	3:Color.DARK_ORANGE,
	4:Color.DARK_RED,
}
var 选中:bool=false:
	set(value):
		选中=value
		刷新背景()
		
var 天赋:天赋数据类
	
signal 被点击(index)

func _ready():
	刷新背景()
	
func 显示天赋(_天赋:天赋数据类):
	天赋=_天赋
	name_label.text=天赋.名字
	name_label.modulate=品质颜色[天赋.品质]
	说明.text="("+天赋.说明+")"
	
func 刷新背景():
	if 选中:
		color_rect.color=Color.DARK_SLATE_GRAY
	else:
		color_rect.color=Color.DIM_GRAY

func _gui_input(event):
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
			被点击.emit(get_index())
